<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        console.log('start'); //1
        var intervalA = setInterval(() => {
            console.log('intervalA');//9
        }, 0);

        setTimeout(() => {
            console.log('timeout');//10

            clearInterval(intervalA);
        }, 0);

        // var intervalB = setInterval(() => {
        //     console.log('intervalB');
        // }, 0);

        var intervalC = setInterval(() => {
            console.log('intervalC');//11
        }, 0);

        new Promise((resolve, reject) => {
            console.log('promise');//2

            for (var i = 0; i < 10000; ++i) {
                i === 9999 && resolve();
            }

            console.log('promise after for-loop');//3
        }).then(() => {
            console.log('promise1');//6
        }).then(() => {
            console.log('promise2');//8

            clearInterval(intervalB);
        });

        new Promise((resolve, reject) => {
            setTimeout(() => {
                console.log('promise in timeout');//12
                resolve();
            });

            console.log('promise after timeout');//4
        }).then(() => {
            console.log('promise4');//13
        }).then(() => {
            console.log('promise5');//14

            clearInterval(intervalC);
        });

        Promise.resolve().then(() => {
            console.log('promise3');//7
        });

        console.log('end')//5
    </script>
</body>

</html>